import { Tag } from "antd"

import { StatusTag } from "@/components/common"
import TooltipText from "@/components/common/tooltipText"
import { useDataMapping, useDigital, useLocale } from "@/hooks"

const useAgentListColumn = () => {
	const { newFormat } = useLocale()
	const { renderFormat, renderCopyNo, renderSlash } = useDigital()
	const { getFromDic } = useDataMapping()
	const agentName = {
		dataIndex: "userName",
		title: newFormat("title.userName"),
		width: 120,
		align: "center",
		render: renderCopyNo
	}
	const joinCode = {
		dataIndex: "joinCode",
		title: newFormat("title.joinCode"),
		width: 120,
		align: "center"
	}
	const proxyLevel = {
		dataIndex: "proxyLevel",
		title: newFormat("title.proxyLevel"),
		width: 120,
		align: "center"
	}
	const proxyLevelName = {
		dataIndex: "proxyLevelName",
		title: newFormat("title.proxyLevelName"),
		width: 120,
		align: "center"
	}
	const proxyLevelCombin = {
		dataIndex: "proxyLevel",
		title: (
			<>
				<div>{newFormat("title.proxyLevel")}</div>
				<div>{newFormat("title.levelName")}</div>
			</>
		),
		width: 120,
		align: "center",
		render: (_text: string, record: any) => (
			<>
				<div>{record["proxyLevel"]}</div>
				<div>{record["proxyLevelName"]}</div>
			</>
		)
	}
	const parentProxy = {
		dataIndex: "parentProxyName",
		title: newFormat("title.parentProxyName"),
		width: 120,
		align: "center",
		render: (text: string) => text ?? "-"
	}
	const topAgentName = {
		dataIndex: "topProxyName",
		title: newFormat("title.topProxyName"),
		width: 120,
		align: "center"
	}
	const merchantNameById = {
		dataIndex: "merchantId",
		title: newFormat("label.belong_merchant"),
		width: 120,
		align: "center",
		render: getFromDic("merchantList")
	}
	const agent_accountType = {
		dataIndex: "accountType",
		title: newFormat("title.accountType"),
		width: 120,
		align: "center",
		render: getFromDic("accountType", false)
	}
	const businessModel = {
		dataIndex: "businessModel",
		title: newFormat("title.businessModel"),
		width: 120,
		align: "center",
		render: (text: string) =>
			newFormat(["label.business_model_both", "label.business_model_cash", "label.business_model_credit"][Number(text)])
	}
	const agent_labelName = {
		dataIndex: "labelName",
		title: newFormat("title.labelName"),
		width: 120,
		align: "center",
		render: (text: string) => text || "-"
	}
	const windControlNameStr = {
		dataIndex: "windControlName",
		width: 120,
		title: newFormat("title.windControlName"),
		align: "center",
		render: (text: string) => text || "-"
	}
	const agent_accountStatus = {
		dataIndex: "accountStatus",
		title: newFormat("title.accountStatus"),
		width: 120,
		align: "center",
		render: (_text: string, record: any) =>
			(() => {
				let context: string = ""
				let color = "green"
				if (record.liquidationStatus) {
					context = newFormat({ id: "label.liquidationStatus" })
					color = "red"
				} else if (record.paymentLockStatus) {
					context = newFormat({ id: "label.account_lock_status" })
					color = "gold"
				} else if (record.loginLockStatus) {
					context = newFormat({ id: "label.login_lock_status" })
					color = "volcano"
				} else if (record.gameLockStatus) {
					context = newFormat({ id: "label.game_lock_status" })
					color = "geekblue"
				} else {
					context = newFormat({ id: "label.account_status_normal" })
					color = "green"
				}

				return (
					<span>
						<Tag color={color}>{context}</Tag>
					</span>
				)
			})()
	}
	const agent_creditLevel = {
		dataIndex: "creditLevel",
		width: 120,
		title: newFormat("title.creditLevel"),
		align: "center"
	}
	const entryAuthority = {
		dataIndex: "entryAuthority",
		width: 120,
		title: newFormat("title.entryAuthority"),
		align: "center",
		render: getFromDic("entrAuthorityType", false)
	}
	const underProxyNum = {
		dataIndex: "underProxyNum",
		width: 120,
		title: newFormat("title.underProxyNum"),
		align: "center"
	}
	const underMemberNum = {
		dataIndex: "underMemberNum",
		width: 120,
		title: newFormat("title.underMemberNum"),
		align: "center"
	}
	const underNumCombin = {
		dataIndex: "underProxyNum",
		width: 200,
		title: (
			<>
				<div>{newFormat("title.underProxyNum")}</div>
				<div>{newFormat("title.underMemberNum")}</div>
			</>
		),
		align: "center",
		render: (_text: string, record: any) => (
			<>
				<div>{record.underProxyNum}</div>
				<div>{record.underMemberNum}</div>
			</>
		)
	}
	const directlyUnderProxyNum = {
		dataIndex: "directlyUnderProxyNum",
		width: 120,
		title: newFormat("title.directlyUnderProxyNum"),
		align: "center"
	}
	const directlyUnderMemberNum = {
		dataIndex: "directlyUnderMemberNum",
		width: 200,
		title: newFormat("title.directlyUnderMemberNum"),
		align: "center"
	}
	const directlyUnderNumCombin = {
		dataIndex: "directlyUnderProxyNum",
		width: 200,
		title: (
			<>
				<div>{newFormat("title.directlyUnderProxyNum")}</div>
				<div>{newFormat("title.directlyUnderMemberNum")}</div>
			</>
		),
		align: "center",
		render: (_text: string, record: any) => (
			<>
				<div>{record.directlyUnderProxyNum}</div>
				<div>{record.directlyUnderMemberNum}</div>
			</>
		)
	}
	const totalDepositAmount = {
		dataIndex: "totalDepositAmount",
		title: newFormat("title.totalDepositAmount"),
		align: "center",
		width: 200,
		render: renderFormat
	}
	const totalDepositNum = {
		dataIndex: "totalDepositNum",
		title: newFormat("title.totalDepositNum"),
		align: "center",
		width: 120
	}
	const depositCombin = {
		dataIndex: "totalDepositAmount",
		title: (
			<>
				<div>{newFormat("title.totalDepositAmount")}</div>
				<div>{newFormat("title.totalDepositNum")}</div>
			</>
		),
		align: "center",
		width: 200,
		render: (_text: string, record: any) => (
			<>
				<div>{renderFormat(record.totalDepositAmount)}</div>
				<div>{record.totalDepositNum}</div>
			</>
		)
	}
	const totalWithdrawAmount = {
		dataIndex: "totalWithdrawAmount",
		title: newFormat("title.totalWithdrawAmount"),
		align: "center",
		width: 200,
		render: renderFormat
	}
	const totalWithdrawNum = {
		dataIndex: "totalWithdrawNum",
		title: newFormat("title.totalWithdrawNum"),
		align: "center",
		width: 120
	}
	const withdrawCombin = {
		dataIndex: "totalWithdrawAmount",
		title: (
			<>
				<div>{newFormat("title.totalWithdrawAmount")}</div>
				<div>{newFormat("title.totalWithdrawNum")}</div>
			</>
		),
		align: "center",
		width: 200,
		render: (_text: string, record: any) => (
			<>
				<div>{renderFormat(record.totalWithdrawAmount)}</div>
				<div>{record.totalWithdrawNum}</div>
			</>
		)
	}
	const borrowAmount = {
		dataIndex: "borrowAmount",
		title: newFormat("title.borrowAmount"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const creditWalletBalance = {
		dataIndex: "creditWalletBalance",
		title: newFormat("title.creditWalletBalance"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const proxyBalance = {
		dataIndex: "centerWalletBalance",
		title: newFormat("title.proxyBalance"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const dispatchAmount = {
		dataIndex: "dispatchAmount",
		title: newFormat("title.dispatchAmount"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const teamCreditTotal = {
		dataIndex: "teamCreditTotal",
		title: newFormat("title.teamCreditTotal"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const credit_amount = {
		dataIndex: "creditQuota",
		title: newFormat("title.creditQuota"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const accountsReceivable = {
		dataIndex: "accountsReceivable",
		title: newFormat("title.accountsReceivable"),
		align: "center",
		width: 120,
		render: renderFormat
	}
	const agent_createdAt = {
		dataIndex: "createdAt",
		title: newFormat("title.createdAt"),
		align: "center",
		width: 200
	}
	const lastLoginTime = {
		dataIndex: "lastLoginTime",
		title: newFormat("title.lastLoginTime"),
		align: "center",
		width: 200
	}
	const agent_timeCombin = {
		dataIndex: "timeCombin",
		title: (
			<>
				<div>{newFormat("title.createdAt")}</div>
				<div>{newFormat("title.lastLoginTime")}</div>
			</>
		),
		align: "center",
		width: 200,
		render: (_text: string, record: any) => (
			<>
				<div>{record.createDt}</div>
				<div>{record.lastLoginTime}</div>
			</>
		)
	}
	const exclusiveDomainName = {
		dataIndex: "exclusiveDomainName",
		title: newFormat("label.exclusiveDomainName"),
		align: "center",
		width: 200
	}
	const domainDesc = {
		dataIndex: "domainDesc",
		title: newFormat("label.domainDesc"),
		align: "center",
		width: 120
	}
	const bindProxy = {
		dataIndex: "bindProxy",
		title: newFormat("label.bindProxy"),
		align: "center",
		width: 120,
		render: renderSlash
	}
	const domainStatus = {
		dataIndex: "domainStatus",
		title: newFormat("label.domainStatus"),
		align: "center",
		width: 120,
		render: (text: number) => {
			return (
				<StatusTag
					type={text === 1 ? "success" : "error"}
					content={text === 1 ? newFormat("label.inWork") : text === 2 ? newFormat("label.stoped") : "-"}
				/>
			)
		}
	}
	const bindingStatus = {
		dataIndex: "bindingStatus",
		title: newFormat("label.bindingStatus"),
		align: "center",
		width: 120,
		render: (text: number) => {
			return (
				<StatusTag
					type={text === 1 ? "success" : "error"}
					content={text === 1 ? newFormat("label.binded") : text === 2 ? newFormat("label.noBind") : "-"}
				/>
			)
		}
	}
	const templateType = {
		dataIndex: "templateType",
		title: newFormat("label.templateType"),
		align: "center",
		width: 120
	}
	const templateName = {
		dataIndex: "templateName",
		title: newFormat("label.redLimit.modelName"),
		align: "center",
		width: 120
	}
	const description = {
		dataIndex: "description",
		title: newFormat("label.template.description"),
		align: "center",
		width: 120
	}
	const useCount = {
		dataIndex: "useCount",
		title: newFormat("label.template.useCount"),
		align: "center",
		width: 120
	}
	const displayOrder = {
		dataIndex: "displayOrder",
		title: newFormat("label.displayOrder"),
		align: "center",
		width: 120
	}
	const domainName = {
		dataIndex: "domainName",
		title: newFormat("label.domainName"),
		align: "center",
		width: 200
	}
	const domainType = {
		dataIndex: "domainType",
		title: newFormat("label.domainType"),
		align: "center",
		width: 120,
		render: getFromDic("enumProxyDomainTypeOperate", false)
	}
	const domainDescription = {
		dataIndex: "description",
		title: newFormat("label.description"),
		align: "center",
		width: 120
	}
	const domain_status = {
		dataIndex: "status",
		title: newFormat("common.status"),
		align: "center",
		width: 120,
		render: (text: string) => {
			return (
				<StatusTag
					type={text === "1" ? "success" : "error"}
					content={text === "1" ? newFormat("label.available") : text === "0" ? newFormat("label.stoped") : "-"}
				/>
			)
		}
	}
	const imageName = {
		dataIndex: "imageName",
		title: newFormat("label.imageName"),
		align: "center",
		width: 120
	}
	const imageType = {
		dataIndex: "imageType",
		title: newFormat("label.imageType"),
		align: "center",
		width: 120,
		render: getFromDic("materialPictureType", false)
	}
	const imageSize = {
		dataIndex: "imageSize",
		title: newFormat("label.imageSize"),
		align: "center",
		width: 120,
		render: getFromDic("pictureSizeType", false)
	}
	const levelId = {
		dataIndex: "id",
		title: newFormat("label.levelId"),
		align: "center",
		width: 60
	}
	const level_name = {
		dataIndex: "levelName",
		title: newFormat("label.name"),
		align: "center",
		width: 120
	}
	// const multiAgentRender = ({ row: any, column: any }) =>
	// 	row.status === 0
	// 		? "-"
	// 		: columnsElements[1].map((item, index) => {
	// 				return lineRender(item.prefix, row[`${column.property}${item.suffix}`], index)
	// 		  })

	// const multiMemberRender = ({ row, column }) =>
	// 	columnsElements[0].map((item, index) => lineRender(item.prefix, row[`${column.property}${item.suffix}`], index))
	// const columnsElements = [
	// 	[
	// 		{
	// 			prefix: newFormat("common.strict_provide"),
	// 			suffix: "RebatePlatform"
	// 		},
	// 		{
	// 			prefix: newFormat("common.agent_provide"),
	// 			suffix: "Rebate"
	// 		}
	// 	],
	// 	[
	// 		{
	// 			prefix: newFormat("common.components.rebate"),
	// 			suffix: "Rebate"
	// 		},
	// 		{
	// 			prefix: newFormat("common.components.share"),
	// 			suffix: "Zhancheng"
	// 		}
	// 	]
	// ]
	const texasRebate = {
		dataIndex: "texasRebate",
		title: newFormat("label.texasRebate"),
		align: "center",
		width: 120,
		render: (text: number, record: any) => {
			return record.userType === 0 ? (
				<>
					<div>{`${newFormat("common.strict_provide")}: ${
						record.texasRebatePlatform ? record.texasRebatePlatform + "%" : "-"
					}`}</div>
					<div>{`${newFormat("common.agent_provide")}: ${record.texasRebate}%`}</div>
				</>
			) : record.status === 0 ? (
				"-"
			) : text ? (
				`${newFormat("label.rebate")}: ${text}%`
			) : (
				"-"
			)
		}
	}
	const texasInsuranceRebate = {
		dataIndex: "texasInsuranceRebate",
		title: newFormat("label.texasInsurance"),
		align: "center",
		width: 200,
		render: (text: number, record: any) => {
			return record.status === 0 ? "-" : `${newFormat("label.rebate")}: ${text}%`
		}
	}
	const valueAddedService = {
		dataIndex: "valueAddedServiceRebate",
		title: newFormat("label.valueAddedService"),
		align: "center",
		width: 140,
		render: (text: number, record: any) => {
			return record.status === 0 ? "-" : `${newFormat("label.rebate")}: ${text}%`
		}
	}
	const rebateStatus = {
		dataIndex: "status",
		title: newFormat("label.status"),
		align: "center",
		width: 120,
		render: (text: number) => {
			return (
				<StatusTag
					type={text === 1 ? "success" : text === 3 ? "warning" : text === 2 ? "error" : "normal"}
					content={newFormat(
						text === 1 ? "label.effected" : text === 0 ? "label.notSet" : text === 2 ? "label.expired" : "label.adjusting"
					)}
				/>
			)
		}
	}
	const rebateUpatedAt = {
		dataIndex: "updatedAt",
		title: newFormat("label.editTime"),
		align: "center",
		width: 200,
		render: renderSlash
	}
	const rebateUpdatedBy = {
		key: "updatedBy",
		align: "center",
		dataIndex: "updatedBy",
		title: newFormat("common.last_updateBy"),
		width: 200,
		render: renderSlash
	}
	const lostEffectDt = {
		dataIndex: "lostEffectDt",
		title: newFormat("label.lostEffectDt"),
		align: "center",
		width: 200,
		render: renderSlash
	}
	const updProxyApplyType = {
		dataIndex: "applyType",
		title: newFormat("agent.audit_apply_time"),
		align: "center",
		width: 150,
		render: getFromDic("updProxyApplyType", false)
	}

	const applyRemark = {
		dataIndex: "applyRemark",
		title: newFormat("agent.apply_info"),
		align: "center",
		width: 150,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	}

	const proxyLevelCombin1 = {
		dataIndex: "proxyLevel",
		title: (
			<>
				<div>{newFormat("title.proxyLevel")}</div>
				<div>{newFormat("title.levelName")}</div>
			</>
		),
		width: 120,
		align: "center",
		render: (_text: string, record: any) => (
			<>
				{record["proxyLevel"]} /{record["proxyLevelName"]}
			</>
		)
	}

	const agentType = {
		key: "type",
		align: "center",
		dataIndex: "type",
		title: newFormat("agent.application_content"),
		width: "50%",
		render: (text: number) => (text === 1 ? "升级总代" : "-")
	}

	return {
		agentName,
		joinCode,
		proxyLevelCombin,
		parentProxy,
		topAgentName,
		merchantNameById,
		agent_accountType,
		businessModel,
		agent_labelName,
		windControlNameStr,
		agent_accountStatus,
		agent_creditLevel,
		entryAuthority,
		underNumCombin,
		directlyUnderNumCombin,
		depositCombin,
		withdrawCombin,
		proxyBalance,
		creditWalletBalance,
		borrowAmount,
		dispatchAmount,
		teamCreditTotal,
		credit_amount,
		accountsReceivable,
		agent_timeCombin,
		totalDepositAmount,
		totalDepositNum,
		totalWithdrawAmount,
		totalWithdrawNum,
		underMemberNum,
		underProxyNum,
		directlyUnderMemberNum,
		directlyUnderProxyNum,
		proxyLevel,
		proxyLevelName,
		agent_createdAt,
		lastLoginTime,
		exclusiveDomainName,
		bindProxy,
		bindingStatus,
		domainStatus,
		domainDesc,
		templateName,
		templateType,
		useCount,
		description,
		domainDescription,
		domainName,
		domainType,
		displayOrder,
		domain_status,
		imageName,
		imageSize,
		imageType,
		levelId,
		level_name,
		texasRebate,
		texasInsuranceRebate,
		valueAddedService,
		rebateStatus,
		rebateUpatedAt,
		rebateUpdatedBy,
		lostEffectDt,
		updProxyApplyType,
		applyRemark,
		proxyLevelCombin1,
		agentType
	}
}

export default useAgentListColumn
